

#手机型号:ad2f78b5

import subprocess
import time
import uiautomator2 as u2

device_serial = "ad2f78b5"
d = u2.connect(device_serial)
def handle_popup():
    # 方法1：ADB模拟点击（坐标模式）
    # adb_path = r"D:\scrcpy\platform-tools-latest-windows\platform-tools\adb.exe"
    # subprocess.run([adb_path, "shell", "input", "tap", "789", "144"])

    # 方法2：uiautomator2控件点击（推荐）
    # device_serial = "ad2f78b5"
    # d = u2.connect(device_serial)
    if d(text="允许").exists:
        d(text="允许").click()
    elif d(text="升级").exists:
        d(text="稍后提醒").click()  # 忽略升级弹窗
    d.click(144, 785)
    time.sleep(5)
    d.swipe(500, 1500, 500, 500, 0.3)
    time.sleep(5)
    d.press("back")
    time.sleep(20)


def Coordinates():
   # 获取当前界面的 XML 层级结构（包含所有元素信息）
   xml = d.dump_hierarchy()
   with open("ui.xml", "w", encoding="utf-8") as f:
    f.write(xml)  # 保存到文件，方便分析
if __name__ == "__main__":
    # 启动scrcpy
    subprocess.Popen([r"D:\scrcpy\scrcpy-win64-v3.3.1\scrcpy-win64-v3.3.1\scrcpy.exe"])
    time.sleep(3)  # 等待弹窗出现

    # 处理弹窗
    #handle_popup()
    Coordinates()